﻿#define _CRT_SECURE_NO_WARNINGS 1

#include<stdlib.h>
#include <stdio.h>
int add(int a, int b)
{
	return a + b;
}
int sub(int a, int b)
{
	return a - b;
}
int mul(int a, int b)
{
	return a * b;
}

int iv(int a, int b)
{
	int c = a / b;
	return c;
}


////int main()
////{
////	int x, y;
////	int input = 1;
////	int ret = 0;
////	do
////	{
////		printf("******************");
////		printf(" 1:add ");
////		printf(" 3:mul ");
////		printf("******************");
////		printf("请选择：");
////		scanf("%d", &input);
////		scanf("%d", &input);
////		switch (input)
////		{
////		case 1:
////			printf("输⼊操作数：");
////			scanf("%d %d", &x, &y);
////				ret = add(x, y);
////				printf("ret = %d\n", ret);
////				break;
////		case 2:
////			printf("输⼊操作数：");
////			scanf("%d %d", &x, &y);
////				ret = sub(x, y);
////			printf("ret = %d\n", ret);
////
////				break;
////		case 3:
////			printf("输⼊操作数：");
////			scanf("%d %d", &x, &y);
////				ret = mul(x, y);
////				printf("ret = %d\n", ret);
////
////				break;
////		case 4:
////			printf("输⼊操作数：");
////			scanf("%d %d", &x, &y);
////				ret = div(x, y);
////				printf("ret = %d\n", ret);
////
////				break;
////		case 0:
////			printf("退出程序\n");
////			break;
////		default:
////			printf("选择错误\n");
////			break;
////		}
////	} while (input);
////	return 0;
////}







//void calc(int(*pf)(int, int))
//{
//	int ret = 0;
//	int x, y;
//	printf("输⼊操作数：");
//	scanf("%d %d", &x, &y);
//	ret = pf(x, y);
//	printf("ret = %d\n", ret);
//}







//int main()
//{
//	int input = 1;
//	do
//	{
//		printf("******************");
//		printf(" 1:add      2:sub");
//		printf(" 3:mul      4:div");
//		printf("******************");
//		printf("请选择：");
//		scanf("%d", &input);
//		switch (input)
//		{
//		case 1:
//			calc(add);
//			break;
//		case 2:
//			calc(sub);
//			break;
//		case 3:
//			calc(mul);
//			break;
//		case 4:
//			calc(div);
//			break;
//		case 0:
//			printf("退出程序\n");
//			break;
//		default:
//			printf("选择错误\n");
//			break;
//		}
//	} while (input);
//
//	return 0;
//}
//



void swap(char* p1, char* p2, size_t with)
{
	for (int i = 0; i < with; i++)
	{
		char tem = *p1;
		*p1 = *p2;
		*p2 = tem;
		p1++;
		p2++;
	}


}






int cmp_int(void* p1, void* p2)
{
	return *(int*)p1 - *(int*)p2;

}

void print(int* p1,int sum)
{
	for (int i = 0; i < sum; i++)
	{

		printf("%d ", p1[i]);

	}

}

void Subble_sort(void* base, size_t sz, size_t with, int (*cmp)(void* p1, void* p2))
{
	int i, j;
	for (i = 0; i < sz - 1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * with, (char*)base + (j + 1) * with) > 0)
			{
				swap((char*)base + j * with, (char*)base + (j + 1) * with, with);

			}
		}
	}

}

int main()
{
	int arr[10] = { 11,2,3,4,66,34,13,15,16,10 };
	Subble_sort(arr, 10, sizeof(arr[1]), cmp_int);

	print(arr, 10);

	return 0;
}
